﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HtmlAgilityPack;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tisonet.Dobrak.Domain.Services.Projections;

namespace Tisonet.Dobrak.Domain.Services.Tests.Projections
{
    [TestClass]
    public class DobrakProjectionsTests
    {
        [TestMethod]
        public void Can_Parse_Empty_Html_Document()
        {
            const string html = "";
            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            var parser = new DobrakHtmlParser(doc.DocumentNode);

            var result = parser.ParseProjections();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }

        [TestMethod]
        public void Can_Parse_Html_With_One_Projections()
        {
            const string html = @"<div class='Datum' rel='d_0'>28. června – pátek, 20.00</div><input class='Datum_cas' ID='2013-06-28' READONLY></input><a href='index.php?den=1' rel='1' class='Nazev'>Solokapr</a>";
            var node = HtmlNode.CreateNode(html);
            var parser = new DobrakHtmlParser(node);

            var result = parser.ParseProjections();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("1", result[0].ID);
            Assert.AreEqual(new DateTime(2013, 6, 28, 20, 0,0), result[0].Date);
            Assert.AreEqual("Solokapr", result[0].Name);
        }


        [TestMethod]
        [DeploymentItem("Tisonet.Dobrak.Domain.Services.Tests\\Projections\\TestFiles\\Projections1.txt")]
        public void Can_Parse_Html_With_More_Projections()
        {
            string html = File.ReadAllText("Projections1.txt");

            var node = HtmlNode.CreateNode(html);
            var parser = new DobrakHtmlParser(node);

            var result = parser.ParseProjections();

            Assert.IsNotNull(result);
            Assert.AreEqual(7, result.Count);
            Assert.AreEqual("1", result[0].ID);
            Assert.AreEqual(new DateTime(2013, 6, 28,21, 30, 0), result[0].Date);
            Assert.AreEqual("V Bruggách", result[0].Name);

            Assert.AreEqual("7", result[6].ID);
            Assert.AreEqual(new DateTime(2013, 7, 4, 21, 30, 0), result[6].Date);
            Assert.AreEqual("Sólokapr", result[6].Name);
        }

         [TestMethod]
         [DeploymentItem("Tisonet.Dobrak.Domain.Services.Tests\\Projections\\TestFiles\\Dobrak.htm")]
        public void Can_Parse_Whole_Dobrak_Html()
        {
            string html = File.ReadAllText("Dobrak.htm");

            var node = HtmlNode.CreateNode(html);
            var parser = new DobrakHtmlParser(node);

            var result = parser.ParseProjections();

            Assert.IsNotNull(result);
            Assert.AreEqual(67, result.Count);
        }
    }
}
